package com.demo.security.access.audit;

/**
 * 功能模型
 * 
 * @author ryuu.kk
 */
public class FunctionModel implements Comparable<FunctionModel>,  java.io.Serializable {
	
	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = 7471084217084205627L;

	/**
	 * 主键ID
	 */
	private final Long id;
	
	/**
	 * 父ID
	 */
	private final Long pid;
	
	/**
	 * 类名
	 */
	private String className;
	
	/**
	 * 方法名
	 */
	private String methodName;
	
	/**
	 * 参数
	 */
	private String parameter;
	
	/**
	 * 功能编码
	 */
	private final String code;
	
	/**
	 * 构造函数
	 * @param level 等级
	 * @param code 编码
	 * @param info 信息
	 */
	public FunctionModel(Long id, Long pid, String code) {
		this.id = id;
		this.pid = pid;
		this.code = code;
	}

	public Long getId() {
		return id;
	}

	public Long getPid() {
		return pid;
	}

	public String getCode() {
		return code;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public String getParameter() {
		return parameter;
	}

	public void setParameter(String parameter) {
		this.parameter = parameter;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof FunctionModel) {
			return obj.equals(this);
		}
		if (obj instanceof String) {
			return obj.equals(this.toString());
		}
		return false;
	}

	@Override
	public int compareTo(FunctionModel o) {
		if (this.getPid() > o.getPid()) {
			return 1;
		} else if(this.getPid().equals(o.getPid())) {
			if (this.getId() > o.getId()) {
				return 1;
			} 
		}
		return -1;
	}
}
